'use strict'

function getBlog(keyword) {
    return new Promise(function (res, rej) {
        $.get('http://localhost:8000/blog?keyword=' + keyword, data => {
            console.log(data);
            res(data)
        })
    })
}

function getBlogId(id) {
    return new Promise(function (res, rej) {
        $.get(`http://localhost:8000/blog/${id}`, data => {
            res(data)
        })
    })
}

function postBlog(obj) {
    return new Promise(function (res, rej) {
        $.post('http://localhost:8000/blog', obj, data => {
            res(data)
        })
    })
}

function putBlog(id, obj) {
    return new Promise(function (res, rej) {
        $.ajax({
            url: `http://localhost:8000/blog/${id}`,
            type: 'put',
            data: obj,
            success: data => { res(data) }
        })
    })
}

function delBlog(id) {
    return new Promise(function (res, rej) {
        $.ajax({
            url: `http://localhost:8000/blog/${id}`,
            type: 'delete',
            success: data => { res(data) }
        })
    })
}